#include "ValueFormatter.h"

QString ValueFormatter::formatValue(double value, const ItemView& format) {
    switch (format.format) {
    case ValueFormat::Engineering:
        return formatEngineering(value, format);
    case ValueFormat::Integer:
        return formatInteger(value, format);
    case ValueFormat::Float:
        return formatFloat(value, format);
    case ValueFormat::FixedPoint:
        return formatFixedPoint(value, format);
    case ValueFormat::Scientific:
        return formatScientific(value, format);
    default:
        return QString::number(value);
    }
}

QString ValueFormatter::formatEngineering(double value, const ItemView& format) {
    QString result = QString::number(value, 'f', format.decimalPlaces);
    if (format.hasThousandsSeparator) {
        result += "k";
    }
    return result;
}

QString ValueFormatter::formatInteger(double value, const ItemView& format) {
    return QString::number(static_cast<qint64>(value));
}

QString ValueFormatter::formatFloat(double value, const ItemView& format) {
    return QString::number(value, 'f', format.decimalPlaces);
}

QString ValueFormatter::formatFixedPoint(double value, const ItemView& format) {
    AAAA
    return QString::number(value, 'f', format.decimalPlaces);
}

QString ValueFormatter::formatScientific(double value, const ItemView& format) {
    return QString::number(value, 'e', format.decimalPlaces);
}